/**
 * 
 */
package com.swim.reservationcoach.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.swim.reservationcoach.entity.ReservationCoach;
import com.swim.reservationcoach.service.ReservationCoachService;

/**
 * 预约私教Controller
 * @author 刘军武
 * @version 2021-05-06
 */
@Controller
@RequestMapping(value = "${adminPath}/reservationcoach/reservationCoach")
public class ReservationCoachController extends BaseController {

	@Autowired
	private ReservationCoachService reservationCoachService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ReservationCoach get(String id, boolean isNewRecord) {
		return reservationCoachService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("reservationcoach:reservationCoach:view")
	@RequestMapping(value = {"list", ""})
	public String list(ReservationCoach reservationCoach, Model model) {
		model.addAttribute("reservationCoach", reservationCoach);
		return "swim/reservationcoach/reservationCoachList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("reservationcoach:reservationCoach:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ReservationCoach> listData(ReservationCoach reservationCoach, HttpServletRequest request, HttpServletResponse response) {
		Page<ReservationCoach> page = reservationCoachService.findPage(new Page<ReservationCoach>(request, response), reservationCoach); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("reservationcoach:reservationCoach:view")
	@RequestMapping(value = "form")
	public String form(ReservationCoach reservationCoach, Model model) {
		model.addAttribute("reservationCoach", reservationCoach);
		return "swim/reservationcoach/reservationCoachForm";
	}

	/**
	 * 保存预约私教
	 */
	@RequiresPermissions("reservationcoach:reservationCoach:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ReservationCoach reservationCoach) {
		reservationCoachService.save(reservationCoach);
		return renderResult(Global.TRUE, text("保存预约私教成功！"));
	}
	
	/**
	 * 删除预约私教
	 */
	@RequiresPermissions("reservationcoach:reservationCoach:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ReservationCoach reservationCoach) {
		reservationCoachService.delete(reservationCoach);
		return renderResult(Global.TRUE, text("删除预约私教成功！"));
	}
	
}